#include "pch.hpp"
#include "CodeEdit.hpp"

using namespace Engine;
using namespace Engine::Edit;




CodeEdit::CodeEdit(QWidget* parent)
	: QTextEdit(parent)
{}
///////////////////////////////////////////////////////////////////////////////////////////////////

CodeEdit::~CodeEdit()
{}
///////////////////////////////////////////////////////////////////////////////////////////////////




void CodeEdit::keyPressEvent(QKeyEvent* event)
{
	// If the user pressed 'Shift' in conjunction with 'Enter', then we will
	// suppress the shift: It causes a visual newline without actually adding
	// a new QTextBlock (which pressing 'Enter' alone does well).
	auto modifiers = event->modifiers();
	if(modifiers.testFlag(Qt::ShiftModifier) && event->matches(QKeySequence::InsertLineSeparator))
	{
		// We'll deliberately remove the shift modifier...
		modifiers ^= Qt::ShiftModifier;

		QKeyEvent newEvent(event->type(), event->key(), modifiers, event->text(), event->isAutoRepeat(), event->count());
		__super::keyPressEvent(&newEvent);
	}
	else
	{
		__super::keyPressEvent(event);
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
